//
//  MissionViewController.m
//  Zhiche-Carriage
//
//  Created by LeeBruce on 16/6/6.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "MissionViewController.h"
#import "TopBackView.h"
#import <Masonry.h>
#import "Common.h"
#import "MineOrderModel.h"
#import "DepartViewController.h"
#import "CrossViewController.h"
#import "LoginViewController.h"

#import "RootViewController.h"

#import "OtherCell.h"//代交车
#import "FinishOrderCell.h"//全部
//#import "ExecuteCell.h"//执行中
#import "ForntCell.h"//待发车

#import "RLNetworkHelper.h"//网络判断
#import "WKProgressHUD.h"//提示框
//下拉刷新
#import <MJRefresh/MJRefresh.h>
#import "NullView.h"
#import "AllOrderViewController.h"
#import "PostPictureVC.h"

//未提车 未交车 待付款 已完成


#define kNumber 2
#define defaultShow 10



@interface MissionViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *buttonArray;
@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic) NSInteger number;
@property (nonatomic,strong) NSMutableArray *imageArray;

@property (nonatomic) int pageNo;
@property (nonatomic) NSInteger pageTotal;
@property (nonatomic) int pageSize;


@property (nonatomic,strong) UIView *netView;
@property (nonatomic,strong) WKProgressHUD *hud;

@property (nonatomic,strong) NullView *nullView;

@end

@implementation MissionViewController

- (void)viewDidLoad {

    [super viewDidLoad];
    
    self.navigationController.navigationBarHidden = YES;
    _number = 0;
    self.pageNo = 1;
    self.pageSize = defaultShow;
    
//    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

    
    self.buttonArray = [NSMutableArray array];
    self.dataArray = [NSMutableArray array];
    self.imageArray = [NSMutableArray arrayWithObjects:@"3_press",@"3_unpress",@"2_press",@"2_unpress",@"icon_all_pre",@"icon_all",nil];
    
    TopBackView *topBackView= [[TopBackView alloc]initViewWithFrame:CGRectMake(0, 0, screenWidth, 64) andTitle:@"我的运单"];
    
    if ([self.hide isEqualToString:@"1"]) {
        topBackView.leftButton.hidden = NO;
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;

        
    } else {
        topBackView.leftButton.hidden = YES;
        
    }
    
    topBackView.rightButton.hidden = YES;
    [topBackView.leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:topBackView];


    
    self.nullView = [[NullView  alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight  - 45 * kHeight) andTitle:@"" andImage:[UIImage imageNamed:@"no_order"]];
    self.nullView.backgroundColor = GrayColor;
    
    Common *c = [[Common alloc]init];
    //创建无网络状态view
    self.netView = [c noInternet:@"网络连接失败，请检查网络设备" and:self action:@selector(NoNetPressBtn) andCGreck:CGRectMake(0, 0, Main_Width, Main_height-64)];

    
    
    self.view.backgroundColor = WhiteColor;
    
    [self initDataSource];
    
    [self initSubViews];

}



-(void)initDataSource
{
   /*
    //假数据
    NSDictionary *dic = [NSDictionary dictionary];
    
    NSString *path = [[NSBundle mainBundle]pathForResource:@"dingdan" ofType:@"txt"];
    
    
    NSString *conters = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    NSData *data = [conters dataUsingEncoding:NSUTF8StringEncoding];
    dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    
    
    for (NSDictionary *diction in dic[@"data"][@"waybills"]) {
        MineOrderModel *model = [[MineOrderModel alloc]init];
        
        [model setValuesForKeysWithDictionary:diction];
        
        
        [self.dataArray addObject:model];
        
    }

    if (self.dataArray.count > 0) {
        [self.tableView reloadData];
    }
    */
    

    NSString *string;
    if (_number == 0) {
        string = mission_waiting ;
        self.nullView.label.text = @"暂无待接单订单";

    } else
    if (_number == 1) {
        string = mission_execution ;
        self.nullView.label.text = @"暂无执行中订单";
    }  else if(_number == 2){
        string = mission_done;
        self.nullView.label.text = @"暂无已完成订单";

    }


    NSString *urlString = [NSString stringWithFormat:@"%@?pageNo=%d&pageSize=%d",string,self.pageNo,self.pageSize];
    
    [Common requestWithUrlString:urlString contentType:application_json finished:^(id responseObj) {
                
        [self.hud dismiss: YES];
        
        if (self.pageNo == 1 && self.dataArray.count > 0) {
            
            [self.dataArray removeAllObjects];
            
        }
        
        self.pageTotal = [responseObj[@"data"][@"page"][@"totalPage"] integerValue];
        
        
        if ([responseObj[@"success"] boolValue]) {
            
            [self.hud dismiss:YES];
            
            
            for (NSDictionary *dic in responseObj[@"data"][@"waybills"]) {
                MineOrderModel *model = [[MineOrderModel alloc]init];
                
                [model setValuesForKeysWithDictionary:dic];
                
                
                [self.dataArray addObject:model];
                
            }
            
            if (self.dataArray.count > 0) {
                [self.nullView removeFromSuperview];
            } else {
                [self.tableView addSubview:self.nullView];
            }
        }
        
        
        [self.tableView reloadData];

        
    } failed:^(NSString *errorMsg) {
        [self.hud dismiss:YES];
        NSLog(@"%@",errorMsg);
    }];
    

}

-(void)showAlertWithString:(NSString *)string
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:string preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *action1   = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *action2   = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:action1];
    [alert addAction:action2];
    
    
    [self presentViewController:alert animated:YES completion:nil];
    
}

-(void)initSubViews
{
    
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, screenWidth, 45 * kHeight)];
    
    NSArray *titleArray = @[@"执行中",@"已完成"];
    
    for (int i = 0; i < titleArray.count; i++) {
        UIButton *topButton = [self backButtonWithString:titleArray[i] andInteger:i andView:topView];
        [topButton addTarget:self action:@selector(topButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        topButton.tag = i + 300;
        
        [self.buttonArray addObject:topButton];
        
        if (i == 0) {
            for (UILabel *lable in [topButton subviews]) {
                if ([lable isKindOfClass:[UILabel class]]) {
                    lable.textColor = YellowColor;
                    for (UIImageView *imageV in [lable subviews]) {
                        if ([imageV isKindOfClass:[UIImageView class]]) {
                            [UIView animateWithDuration:0.2 animations:^{
                                imageV.hidden = NO;
                                
                            }];
                        }
                    }
                    
                }
                
            }
            
            for (UIImageView *img in [topButton subviews]) {
                if ([img isKindOfClass:[UIImageView class]]) {
                    img.image = [UIImage imageNamed:self.imageArray[0]];
                }
            }
            
            
        }
    }
    

    if ([self.hide isEqualToString:@"1"]) {
        
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64 + 45 * kHeight, screenWidth, screenHeight - (64 + 45 * kHeight)) style:UITableViewStyleGrouped];
    } else {
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64 + 45 * kHeight, screenWidth, screenHeight - 64  - 45 * kHeight - 48 * kHeight) style:UITableViewStyleGrouped];
        
    }

    
    [self.view addSubview:topView];

    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = GrayColor;
    self.tableView.tableFooterView = [[UIView alloc]init];
    
    [self.view addSubview:self.tableView];
    
    //mj
    [self.tableView.mj_header beginRefreshing];
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(downRefresh)];
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(upRefresh)];
    
    //无网络状态
    [self createNetWorkAndStatue];

}


-(void)createNetWorkAndStatue{
    
    //判断是否有网
    [self judgeNetWork];
    //创建加载状态
}

//判断是否有网
-(void)judgeNetWork{
    if (![RLNetworkHelper isConnectedToNetwork]) {
        [self.tableView addSubview:self.netView];
        self.hud = [WKProgressHUD showInView:self.view withText:@"加载中" animated:YES];
        
    }
    else{
        [self.netView removeFromSuperview];
        [self initDataSource];
    }
}
//无网络状态
-(void)NoNetPressBtn{
    if ([RLNetworkHelper isConnectedToNetwork]) {
        [self.netView removeFromSuperview];
        [self initDataSource];
    } else {
        [self.hud dismiss:YES];
    }
}

-(void)downRefresh{
    
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
    self.pageNo = 1;
    
    [self judgeNetWork];
}
-(void)upRefresh{
    
    if (self.pageNo != (int)self.pageTotal) {
        self.pageNo ++;
        [self judgeNetWork];
        [self.tableView.mj_footer endRefreshing];
    }else{
        self.tableView.mj_footer.state = MJRefreshStateNoMoreData;
    }
    [self.tableView.mj_header endRefreshing];
}


-(void)topButtonAction:(UIButton *)sender
{
    
    for (int i = 0; i < self.buttonArray.count; i++) {
        UIButton *button = (UIButton *)self.buttonArray[i];
        
        if (button.tag == sender.tag) {
            
            for (UIImageView *img in [sender subviews]) {
                if ([img isKindOfClass:[UIImageView class]]) {
                    img.image = [UIImage imageNamed:self.imageArray[(sender.tag - 300) * 2]];
                }
            }
            
            for (UILabel *lable in [sender subviews]) {
                
                if ([lable isKindOfClass:[UILabel class]]) {
                    
                    lable.textColor = YellowColor;
                    
                    for (UIImageView *imageV in [lable subviews]) {
                        
                        if ([imageV isKindOfClass:[UIImageView class]]) {
                            [UIView animateWithDuration:0.2 animations:^{
                                imageV.hidden = NO;
                                
                            }];
                        }
                    }
                    
                }
                
            }
        } else {
            
            for (UIImageView *img in [button subviews]) {
                if ([img isKindOfClass:[UIImageView class]]) {
                    img.image = [UIImage imageNamed:self.imageArray[i * 2 + 1]];
                }
            }
            
            
            for (UILabel *lable in [button subviews]) {
                if ([lable isKindOfClass:[UILabel class]]) {
                    
                    lable.textColor = littleBlackColor;
                    
                    for (UIImageView *imageV in [lable subviews]) {
                        
                        if ([imageV isKindOfClass:[UIImageView class]]) {
                            [UIView animateWithDuration:0.2 animations:^{
                                imageV.hidden = YES;
                                
                            }];
                        }
                    }
                    
                }
                
            }
            
        }
        
        
    }
    
    [self present];

    self.pageNo = 1;
    _number = sender.tag - 300;
    
    [self.tableView reloadData];
    
    [self initDataSource];
    
    
}

-(void)present
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    NSString *string = [userDefaults objectForKey:@"login"];
    
    if (string == nil ) {
        
        LoginViewController *loginVC = [[LoginViewController alloc]init];
        loginVC.topBackView.leftButton.hidden = YES;
        UINavigationController * loginNC = [[UINavigationController alloc]initWithRootViewController:loginVC];
        loginVC.backToFirst = @"1";
        
        [self presentViewController:loginNC animated:YES completion:nil];
        
    }
    
}


-(UIButton *)backButtonWithString:(NSString *)string andInteger:(int)a andView:(UIView *)view
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(15 + (screenWidth - 30)/kNumber * a, 0, (screenWidth - 30)/kNumber, 45 * kHeight);
    
    
    UIImageView *logoImageV = [[UIImageView alloc]init];
//    logoImageV.layer.cornerRadius = 10;
//    logoImageV.layer.masksToBounds = YES;
    [button addSubview:logoImageV];
    [logoImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(button);
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.top.mas_equalTo(5 * kHeight);
        
    }];
    logoImageV.image = [UIImage imageNamed:self.imageArray[2 * a + 1]];

    
    UILabel *titleLabel = [[UILabel alloc]init];
    [button addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(button);
        make.width.equalTo(button);
        make.height.mas_equalTo(43 * kHeight - 20) ;
        make.top.mas_equalTo(logoImageV.mas_bottom).offset( -2 * kHeight);
        
    }];
    
    titleLabel.font = Font(9);
    titleLabel.text = string;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [titleLabel sizeToFit];
    
    CGRect rect = titleLabel.frame;
    
    //下面黑线
    UIImageView *imageV = [[UIImageView alloc]init];
    [titleLabel addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(-2 * kHeight);
//        make.top.mas_equalTo(titleLabel.frame.size.height - 1);
        make.centerX.equalTo(titleLabel);
        make.height.mas_equalTo(1 * kWidth);
        make.width.mas_equalTo(rect.size.width + 80);
        
    }];
    
    imageV.backgroundColor = YellowColor;
    imageV.hidden = YES;
    
    if (a == 1) {
        UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 45 *kHeight - 0.5, screenWidth, 0.5)];
        lable.backgroundColor = Color_RGB(200, 201, 204, 1);
        
        [view addSubview:lable];
    }
    
    [view addSubview:button];
    
    return button;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return self.dataArray.count;
//    return 3;
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        
    if (_number == 0) {
        
        NSString *cellString = @"fukuanCell";
        ForntCell *cell = [tableView dequeueReusableCellWithIdentifier:cellString];
        if (!cell) {
            
        cell = [[ForntCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString];
        
        }
        
       //提车照片
        [cell.getButton addTarget:self action:@selector(getButton:) forControlEvents:UIControlEventTouchUpInside];
        cell.getButton.tag = indexPath.section + 1000;
        
        //交车照片
        [cell.giveButton addTarget:self action:@selector(giveButton:) forControlEvents:UIControlEventTouchUpInside];
        cell.giveButton.tag = indexPath.section + 1200;
        //确认发车
        [cell.confirmButton addTarget:self action:@selector(confirmButton:) forControlEvents:UIControlEventTouchUpInside];
        cell.confirmButton.tag = indexPath.section + 1400;
        
        
        
        if (self.dataArray.count > 0) {
            cell.model = self.dataArray[indexPath.section];
            
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
        
    } else   {
        
        NSString *cellString = @"otherCell";
        OtherCell *cell = [tableView dequeueReusableCellWithIdentifier:cellString];
        if (!cell) {
            cell = [[OtherCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString];
        }
        
//        [cell.detailButton addTarget:self action:@selector(detailButton:) forControlEvents:UIControlEventTouchUpInside];
//        
//        cell.detailButton.tag = indexPath.section + 2000;

        if (self.dataArray.count > 0) {
            cell.model = self.dataArray[indexPath.section];
            
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
        
    }
    
    /*
    else {
        
        NSString *cellString = @"finishCell";
        FinishOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellString];
        if (!cell) {
            cell = [[FinishOrderCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString];
        }
        
        [cell.detailButton addTarget:self action:@selector(detailButton:) forControlEvents:UIControlEventTouchUpInside];
        
        cell.detailButton.tag = indexPath.section + 3000;
//
        if (self.dataArray.count > 0) {
            cell.model = self.dataArray[indexPath.section];
            
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;

        
    }
     */
}

#pragma mark button
-(void)getButton:(UIButton *)sender
{
    MineOrderModel *model = self.dataArray[sender.tag - 1000];
    PostPictureVC *postVC = [[PostPictureVC alloc]init];
    postVC.titleString = @"提车照片";
    postVC.orderId = model.ID;
    postVC.orderNumber = model.waybillCode;
    [self.navigationController pushViewController:postVC animated:YES];
}

-(void)giveButton:(UIButton *)sender
{
    MineOrderModel *model = self.dataArray[sender.tag - 1200];
    PostPictureVC *postVC = [[PostPictureVC alloc]init];
    postVC.titleString = @"交车照片";
    postVC.orderId = model.ID;
    postVC.orderNumber = model.waybillCode;
    [self.navigationController pushViewController:postVC animated:YES];

}
//确认发车
-(void)confirmButton:(UIButton *)sender
{
    MineOrderModel *model = self.dataArray[sender.tag - 1400];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认发车" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
     UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
         
         
         [WKProgressHUD showInView:self.view withText:@"" animated:YES];
         
         Common *c = [[Common alloc]init];
         [c afPostRequestWithUrlString:waybill_start parms:@{@"id":model.ID} finishedBlock:^(id responseObj) {
             
             NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableLeaves error:nil];
             
             [WKProgressHUD dismissInView:self.view animated:YES];
             
             if ([dic[@"success"] boolValue]) {
                 
                 [WKProgressHUD popMessage:dic[@"message"] inView:self.view duration:1.5 animated:YES];

                 
                 [self initDataSource];
                 
             }
             
             
         } failedBlock:^(NSString *errorMsg) {
             [WKProgressHUD dismissInView:self.view animated:YES];

             NSLog(@"%@",errorMsg);
         }];

         
         
     }];
    
    [alert addAction:action1];
    [alert addAction:action2];
    
    [self presentViewController:alert animated:YES completion:nil];
    
   
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_number == 1) {
        
        return  162.5 * kHeight;
    } else {
        
        MineOrderModel *model = [[MineOrderModel alloc]init];

        if (self.dataArray.count > 0) {
            
           model  = self.dataArray[indexPath.section];
            
            if ([model.status integerValue] == 30 || [model.status integerValue] == 50 || [model.status integerValue] == 60 ) {
                
                return 207 * kHeight;
            } else {
                return  162.5 * kHeight;

            }
        } else {
            return 0;
        }

//        return 207 * kHeight;

    }

}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 8;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//
    MineOrderModel *model = [[MineOrderModel alloc]init];
    model = self.dataArray[indexPath.section];
    
    
    DepartViewController *departVC = [[DepartViewController alloc]init];
    
    departVC.orderId = model.ID;
    departVC.hiddenPriceTeger = [model.bidderType integerValue];
    //公司派单要隐藏价格
    if ([model.bidderType integerValue] == 10) {
        departVC.hiddenPriceTeger = NO;
    } else {
        departVC.hiddenPriceTeger = YES;
    }
    
    
    [self.navigationController pushViewController:departVC animated:YES];
    
//    if (_number == 0) {
//        
//        DepartViewController *departVC = [[DepartViewController alloc]init];
//       
//        departVC.orderId = model.ID;
//        departVC.hiddenPriceTeger = [model.bidderType integerValue];
//        
//        [self.navigationController pushViewController:departVC animated:YES];
//
//    } else if(_number == 1) {
//        
//        CrossViewController *crossVC = [[CrossViewController alloc]init];
//  
//        crossVC.orderId = model.ID;
//        crossVC.hiddenPriceTeger = [model.bidderType integerValue];
//
//        [self.navigationController pushViewController:crossVC animated:YES];
//
//    } else {
////        
////        PostPictureVC *postVC = [[PostPictureVC alloc]init];
////        postVC.titleString = @"交车照片";
////        [self.navigationController pushViewController:postVC animated:YES];
//        
//        
//        AllOrderViewController *allVC = [[AllOrderViewController alloc]init];
//        allVC.orderId = model.ID;
//        
//        allVC.hiddenPriceTeger = [model.bidderType integerValue];
//
//        NSLog(@"%@",model.bidderType);
//
//        [self.navigationController pushViewController:allVC animated:YES];
//    }
//
//
//    OrderDetailRootVC *orderVC = [[OrderDetailRootVC alloc]init];
//    
//    if (_number == 0) {
//        orderVC.status = @"待收款";
//    } else {
//        orderVC.status = @"全部";
//    }
//    
//    orderVC.orderId = model.ID;
//
//    [self.navigationController pushViewController:orderVC
//                                         animated:YES];
    
}

#pragma mark 左滑事件
//-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    
//}




-(void)viewWillAppear:(BOOL)animated
{
    

    [self.navigationController setNavigationBarHidden:YES];

    RootViewController *rootVC = [RootViewController defaultsTabBar];
    if ([self.hide isEqualToString:@"1"]) {
        
        [rootVC setTabBarHidden:YES];
        
    } else {
        
        [rootVC setTabBarHidden:NO];
        
    }
    
    [self initDataSource];
    
}
//
//-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//
//
//    UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"disenable" handler:nil];
//
//    UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"emjoy👍" handler:nil];
//    
//
//    return @[action2,action3];
//}

-(void)viewDidAppear:(BOOL)animated
{
    RootViewController *rootVC = [RootViewController defaultsTabBar];
    
    
    if ([rootVC.rootString isEqualToString:@"1"]) {
        
        [self present];
        
        rootVC.rootString = @"2";
        
    }
    
    
    
    if ([self.hide isEqualToString:@"1"]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        
    } else {
     
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;

    }
    

    
    
}




-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
